package com.hurt.competition.admin.controller;

import com.hurt.competition.admin.dto.AdLoginReq;
import com.hurt.competition.admin.dto.ApiResult;
import com.hurt.competition.admin.util.ApiResultHandler;
import com.hurt.competition.admin.service.impl.AdLoginServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin/ad")

public class LoginController {
    @Autowired
    private AdLoginServiceImpl adLoginService;
    @PostMapping("/login")
    public ApiResult login(@RequestBody AdLoginReq login) {

        String admin_name = login.getUsername();
        String admin_pwd = login.getPassword();
        AdLoginReq adminRes = adLoginService.adminLogin(admin_name, admin_pwd);
        if (adminRes != null) {
            return ApiResultHandler.buildApiResult(200, "请求成功", adminRes);
        }
        return ApiResultHandler.buildApiResult(400, "请求失败", null);
    }
}
